GBML manual / Backgrounds

zoom_background_position

Moves the room’s zoomable background so that its picture’s top-left corner is at the screen position (x, y).

Works differently on Game Boy - The Game Boy shows a zoomable background as the room's picture, its own size: it cannot be made bigger, smaller or turned. The picture is cut to 256 by 256 pixels and goes round every 256 pixels. It moves sideways or up and down, not both at once.

Works differently on Game Boy Color - The Game Boy Color shows a zoomable background as the room's picture, its own size: it cannot be made bigger, smaller or turned. The picture is cut to 256 by 256 pixels and goes round every 256 pixels. It moves sideways and up and down.

Sega Genesis: not available

On other consoles this differs: see Side by side and How the consoles differ.

Syntax

zoom_background_position(x, y)

Arguments

NameType
xreal
yreal

Returns

Nothing.

Description

Moves the room's zoomable background so that its picture's top-left corner is at the screen position (x, y). It does nothing in a room that has no zoomable background.

The numbers are screen numbers: (0, 0) is the top-left pixel of the screen, not the top-left corner of the room. That is on purpose. A zoomable background does not scroll with the camera, so a map screen stays where you put it while the camera moves behind it. If you want it to follow the world anyway, hand it the camera's position yourself: zoom_background_position(-camera_x(), -camera_y()).

A new zoomable background starts with its top-left corner at the screen's top-left, (0, 0).

It is cheap enough to call every frame, so panning with the d-pad is just a matter of changing the numbers a little each frame.

This call only moves the picture. It does not move the point the picture zooms and turns around: that is zoom_background_focus, and it starts as the middle of the screen.

Example

// Step event of the object that runs the map screen. Its own x and y say where on the map we are looking.
x += (btn_held(BTN_RIGHT) ? 2 : 0) - (btn_held(BTN_LEFT) ? 2 : 0);
y += (btn_held(BTN_DOWN) ? 2 : 0) - (btn_held(BTN_UP) ? 2 : 0);
zoom_background_position(-x, -y);

Holding right makes x grow, so the picture slides left and you see more of the map to the right: the way dragging a real map works, from the point of view of someone walking across it.

On the GBA

A no-op in a room that has no zoomable background. The numbers are SCREEN numbers, counted from the screen’s top-left pixel, not room numbers: the picture does not scroll with the camera, so a map screen stays put while the camera moves. To make it follow the world, feed it the camera yourself (`zoom_background_position(-camera_x(), -camera_y())`). A new zoomable background starts with its top-left corner at the screen’s top-left, (0, 0). Cheap enough to call every frame. It zooms and turns about the focus point, not about this corner: see zoom_background_focus.

See also: Zoomable backgroundszoom_background_scalezoom_background_focuszoom_background_rotationdraw_background